package com.deram.ctin.common.utils;

import com.google.common.collect.Lists;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public class MultipartUtils {

    public static final List<String> IMAGE_CONTENT_TYPE = Lists.newArrayList("image/gif", "image/jpeg", "image/jpg", "image/png", "image/x-png", "image/pjpeg");

    private MultipartUtils(){}

    public static void checkImage(MultipartFile mf, Long maxSize){
        ValidateUtils.isTrue(null != mf && !mf.isEmpty(), "上传的图片不能为空");
        ValidateUtils.in(mf.getContentType(), IMAGE_CONTENT_TYPE, "上传的图片类型错误");
        if(null != maxSize){
            ValidateUtils.isTrue(mf.getSize() <= maxSize, "上传的图片过大");
        }
    }
}
